package io.jee.runshan.dao.impl;

import io.jee.medusa.orm.Hibernate4DaoSupport;
import io.jee.runshan.dao.IInformationDao;
import io.jee.runshan.domain.Information;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

@Repository
public class InformationDaoImpl extends Hibernate4DaoSupport<Information> implements IInformationDao{

	@Override
	public void updateFloorOnTop(Integer id) {
		Information floor = this.get(id);
		if (floor == null) {
			return;
		}
		StringBuffer hql = new StringBuffer("update Information t0 set t0.orderIndex = t0.orderIndex + 1 where t0.type = :type");
		hql.append(" and t0.orderIndex < :currentIndex");
		Query query = this.getSession().createQuery(hql.toString());
		query.setInteger("type", Information.TYPE_FLOOR).setInteger("currentIndex", floor.getOrderIndex());
		query.executeUpdate();
		
		floor.setOrderIndex(1);
		this.update(floor);
	}
}
